using System.Collections.Generic;
using System.Diagnostics;
using Gameplay.PVE.Entity;
using UnityEngine;

namespace Gameplay.PVE
{
    public class BattleUnitLog:MonoBehaviour
    {
        public class LogData
        {
            public bool isShowDetail;
            public string content;
            public string stackTrace;
        }
        public List<LogData> logList = new List<LogData>();
        public Dictionary<int,LogData> staticLogDic = new Dictionary<int,LogData>();

        private BattleUnit unit;
        
        public void Init(BattleUnit unit)
        {
            this.unit = unit;
        }
        
        public void AddToLog(string content,string luaStackTrace = null)
        {
            if (!PveGlobalVlues.ShowBattleUnitLog)
            {
                return;
            }
            //content = PveManager.frame + " " + content;
            var data = new LogData
            {
                content = content,
                stackTrace = luaStackTrace ?? new StackTrace(true).ToString(),
            };
            logList.Add(data);
            if (logList.Count > 100)
            {
                var newList = new List<LogData>();
                for (int i = 50; i < logList.Count; i++)
                {
                    newList.Add(logList[i]);
                }

                logList = newList;
            }
        }

        public void AddToStaticLog(int type, string content, string luaStackTrace = null)
        {
            if (!PveGlobalVlues.ShowBattleUnitLog)
            {
                return;
            }
            var data = new LogData
            {
                content = content,
                stackTrace = luaStackTrace ?? new StackTrace(true).ToString(),
            };
            staticLogDic[type] = data;
        }

        public void Clear()
        {
            logList.Clear();
        }
    }
}